package listener;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA
 * Description
 * User：chenshu
 * Date：2023-12-20
 * Time：10:30
 */
//@WebListener
public class MyListener implements ServletRequestListener {
    private int icount = 0;
    @Override
    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
    }

    @Override
    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest request =
                (HttpServletRequest) servletRequestEvent.getServletRequest();
        if (request.getRequestURI().equals(request.getContextPath() + "/shows")) {
            icount++;
            System.out.println(icount);
            request.getServletContext().setAttribute("count", new Integer(icount));
        }
    }
}
